package com.action.log;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.beans.log.LogReply;
import com.business.log.LogReplyBus;
import com.config.SystemGlobals;

public class ManageLogReply extends HttpServlet {

	private static final long serialVersionUID = 1L;
	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		String contentType = SystemGlobals.getValue("contentType");
		PrintWriter out = response.getWriter();
		response.setContentType(contentType);

		if (request.getParameter("deleted") != null) {
			String[] replyIds = request.getParameterValues("deleted");
			LogReplyBus lrb = new LogReplyBus();
			for (int i = 0; i < replyIds.length; i++) {
				lrb.del(replyIds[i]);
			}
			out
					.println("<script>alert(\"删除选定回复成功\");window.location=\"admin/blog/logreplylist.jsp\";</script>");
			out.close();
		}
		if (request.getParameter("edit") != null) {
			String replyContent = request.getParameter("replycontent");

			String replyTime = request.getParameter("replytime");
			String nickname = request.getParameter("nickname");
			String logNo = request.getParameter("logno");
			LogReply lr = new LogReply();
			lr.setNickname(nickname);
			lr.setLogNo(logNo);
			lr.setReplyContent(replyContent);
			lr.setReplyTime(replyTime);

			String replyId = request.getParameter("id");
			LogReplyBus lrb = new LogReplyBus();
			lrb.update(lr, replyId);
			out
					.println("<script>alert(\"编辑回复成功\");window.location=\"admin/blog/logreplylist.jsp\";</script>");
			out.close();
		}
	}

}
